import sys
from socket import *


serverName = sys.argv[1]
serverPort = int(sys.argv[2])
filename = sys.argv[3]

#请求方式 GET方法
request_head_1 ='GET / '

request_head_2 = ' \
    HTTP/1.1\nHost: 127.0.0.1:48\nConnection: keep-alive\nUpgrade-Insecure-Request: 1\n\
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3\n\
    Purpose: prefetch\n\
    Accept-Encoding: gzip, deflate, br\n\
    Accept-Language: zh-CN,zh;q=0.9,en;q=0.8'
request_head = request_head_1+filename+request_head_2

clientSocket = socket(AF_INET, SOCK_STREAM) #IPv4 TCP
clientSocket.connect((serverName,serverPort))

clientSocket.send(request_head.encode())

##看看响应报文发过来的是什么
for i in range(2):
    mod = clientSocket.recv(1024)
    print(mod.decode())

clientSocket.close()